//
//  PauseViewController.m
//  ToucheTouche
//
//  Created by Jordan Montel on 10/01/12.
//  Copyright 2012 __MyCompanyName__. All rights reserved.
//

#import "PauseViewController.h"
#import "GameAventureViewController.h"
#import "MenuViewController.h"
#import "Level.h"

@implementation PauseViewController

@synthesize buttonHelp, buttonMenu, buttonNewGame, buttonBackGame;
@synthesize gameAventureViewController;
@synthesize labelScore, labelTime, labelLevel, labelLife;
@synthesize delegate;

- (IBAction)pushHelp {
    levelHelpViewController = [[LevelHelpViewController alloc] initWithNibName:@"LevelHelpViewController" bundle:nil];
    levelHelpViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:levelHelpViewController animated:YES];
    [levelHelpViewController release];
}

- (IBAction)pushMenu {
    MenuViewController *menuViewController = [[MenuViewController alloc] initWithNibName:@"MenuViewController" bundle:nil];
    menuViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:menuViewController animated:YES];
    [menuViewController release];
}

- (IBAction)backGame {
    [self.gameAventureViewController timerImage];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"TimerNotification" object:nil];
    
    [[Level sharedLevel] setIntTimeLevel:[[Level sharedLevel] intTimeLevel]];
    
    [self.gameAventureViewController timerLevelBackToGame];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"TimerLevelBackToGameNotification" object:nil];
    
    [self setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
    [self dismissModalViewControllerAnimated:YES];
}

- (IBAction)newGame {
    [self.gameAventureViewController restartGame];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"RestartNotification" object:nil];
    
    [self setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
    [self dismissModalViewControllerAnimated:YES];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [buttonMenu release];
    [buttonNewGame release];
    [buttonBackGame release];
    [buttonHelp release];
    [gameAventureViewController release];
    
    [labelScore release];
    [labelTime release];
    [labelLevel release];
    [labelLife release];
    
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    //self.view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.2f];
    self.view.backgroundColor = [UIColor clearColor];
    
    labelScore.text = [NSString stringWithFormat:@"%.0f", [[Level sharedLevel] floatScore]];
    labelLife.text = [NSString stringWithFormat:@"%.0f / 100", [[Level sharedLevel] floatLife]];
    labelTime.text = [NSString stringWithFormat:@"%d", [[Level sharedLevel] intTimeLevel]];
    labelLevel.text = [NSString stringWithFormat:@"%d", [[Level sharedLevel] intCurrentLevel]];
}

- (void)viewDidUnload
{
    [self setButtonMenu:nil];
    [self setButtonNewGame:nil];
    [self setButtonBackGame:nil];
    [self setButtonHelp:nil];
    [self setLabelScore:nil];
    [self setLabelTime:nil];
    [self setLabelLevel:nil];
    [self setLabelLife:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

@end
